from qiniu import Auth, put_file, etag
import qiniu.config
class QiniuManage:
    def __init__(self, ak, sk, bucket_name):
        self.access_key = ak
        self.secret_key = sk
        self.bucket_name = bucket_name
    def auth(self):
        q = Auth(self.access_key, self.secret_key)
        return q
    def upload_file(self, file_name, file_path):
        token = self.auth().upload_token(self.bucket_name, expires=3600 * 24 * 3)
        ret, info = put_file(token, key=file_name, file_path=file_path, version='v2')
        return ret, info

    def get_token(self):
        token = self.auth().upload_token(self.bucket_name, None, 3600 * 24 * 3)
        print(token)
        return token

    def download_file(self, key):
        bucket_addr = 'spxayq49k.hd-bkt.clouddn.com'
        base_url = f'http://{bucket_addr}/{key}'
        return base_url


def qiuniuImg():
    QINIU_ACCESS_KEY = 'D_nlMP-AK8JAq4f14a6xtTpbqcvVv8BRdk3L8Tfz'
    QINIU_SECRET_KEY = '49E_OMjHLFw_8uy6rWEeVh0BG9xCfF7uJ311K2Qy'
    QINIU_BUCKET_NAME = 'patient2025'
    qiniu = QiniuManage(QINIU_ACCESS_KEY, QINIU_SECRET_KEY, QINIU_BUCKET_NAME)
    print("<<<<<", qiniu.get_token())
    return qiniu

